package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.system.domain.SysDocument;
import com.pureut.system.domain.vo.SysDocumentVo;
import com.pureut.system.service.ISysDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 单据配置
 * @Param
 * @return 结果
 * @Date 22-11-22
 * @Author hl
 **/

@RestController
@RequestMapping("/document")
public class SysDocumentController extends BaseController {

    @Autowired
    private ISysDocumentService sysDocumentService;

    /**
     * 获取单据配置
     */
    @RequiresPermissions("system:billconfig:list")
    @GetMapping("/list")
    public TableDataInfo list(SysDocumentVo sysDocument)
    {
        startPage();
        List<SysDocument> list = sysDocumentService.selectDocumentList(sysDocument);
        return getDataTable(list);
    }

    /**
     * 根据id查询详情
     */
    @RequiresPermissions("system:billconfig:query")
    @GetMapping(value = "/{docId}")
    public AjaxResult getInfo(@PathVariable long docId) {
        return AjaxResult.success(sysDocumentService.selectDocumentListById(docId));
    }

    /**
     * 删除单据配置
     */
    @RequiresPermissions("system:billconfig:remove")
    @Log(title = "编码配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{docId}")
    public AjaxResult remove(@PathVariable("docId") String docId) throws Exception {
        return toAjax(sysDocumentService.deleteDocumentById(docId));
    }

    /**
     * 新增单据配置
     */
    @RequiresPermissions("system:billconfig:add")
    @Log(title = "编码配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody SysDocumentVo sysDocumentVo) throws Exception {
        return toAjax(sysDocumentService.insertDocument(sysDocumentVo));
    }

    /**
     * 修改单据配置
     */
    @RequiresPermissions("system:billconfig:edit")
    @Log(title = "编码配置", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody SysDocumentVo sysDocumentVo) throws Exception {
        return toAjax(sysDocumentService.updateDocument(sysDocumentVo));
    }

    /**
     * 根据配置单据查询单据配置详情
     * 远程调用接口
     */
    @GetMapping(value = "/docConfigById/{docConfig}")
    public AjaxResult getInfoConfig(@PathVariable Long docConfig) {
        return AjaxResult.success(sysDocumentService.selectDocumentConfigById(docConfig));
    }

    /**
     * 根据权限码返回生成编码
     * 远程调用接口
     */
    @GetMapping(value = "/authorityCoding")
    public String authorityCoding(String docConfig) throws Exception {
        return sysDocumentService.selectAuthorityCoding(docConfig);
    }

}
